package com.cndw.kungfu.model.player;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.cndw.commons.util.BlankUtils;
import com.cndw.kungfu.config.Constants;
import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.config.DiscipleConfig;
import com.cndw.kungfu.config.EquipType;
import com.cndw.kungfu.domain.Goods;
import com.cndw.kungfu.domain.GoodsExt;
import com.cndw.kungfu.domain.Pet;
import com.cndw.kungfu.domain.PetMode;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.Skill;
import com.cndw.kungfu.domain.SkillMode;
import com.cndw.kungfu.domain.UnionSkillConfig;
import com.cndw.kungfu.domain.Vocation;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.disciple.DiscipleDower;
import com.cndw.kungfu.model.disciple.DiscipleFeature;
import com.cndw.kungfu.model.disciple.PlayerMartial;
import com.cndw.kungfu.model.disciple.domain.Disciple;
import com.cndw.kungfu.model.disciple.domain.DiscipleMode;
import com.cndw.kungfu.model.goods.domain.ModeGoodsInlay;
import com.cndw.kungfu.model.goods.domain.ModeGoodsStarSuit;
import com.cndw.kungfu.model.pet.domain.PetSoul;
import com.cndw.kungfu.model.pet.domain.Soul;
import com.cndw.kungfu.model.player.domain.Artifact;
import com.cndw.kungfu.model.player.domain.Dragon;
import com.cndw.kungfu.model.skill.PlayerSkill;
import com.cndw.kungfu.model.skill.SkillGird;
/**
 * 玩家战力计算
 * 
 * @author Everest
 *
 */
public class FormulaScore {

	public static int[][] calcAllScore(Player player) {
		int[][] power = new int[7][5];
		power[1] = calcPlayerScore(player);// 角色基础战力
		power[2] = calcEquipScore(player);// 装备
		power[3] = calcSkillScore(player);// 技能
		power[4] = calcDiscipleScore(player);// 徒弟
		power[5] = calcPetScore(player);// 宠物
		power[6] = calcOtherScore(player);// 其它
		power[0][0] = power[1][0] + power[2][0] + power[3][0] + power[4][0] + power[5][0]+ power[6][0];// 综合战力
		return power;
	}
	
	/**
	 * 玩家其它战力组成
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcOtherScore(Player player) {
		int[] result = new int[4];
		
		int[] calcArr = new int[15];
		//神器战力
		Artifact artifact = player.getDataInfo().getArtifact();
		if (artifact != null) {
			//上古神器加成
			int[] actAdd = artifact.getAttris();
			for (int i = 0; i < actAdd.length; i++) {
				calcArr[i] = actAdd[i];
			}
			result[1] = calcPower(calcArr) * 2;//上古神器
		}
		
		//龙纹战力
		int lw = player.getDataInfo().intDataGet(ConstantsIntKey.lw);
		if (lw > 0) {
			Dragon dragon = Dragon.getOne(lw);
			if (dragon!=null) {
				try {
					initArr(calcArr);
					calcArr[5] = dragon.getAddsVar()[0];
					calcArr[6] = dragon.getAddsVar()[1];
					calcArr[7] = dragon.getAddsVar()[2];
					calcArr[9] = dragon.getAddsVar()[3];
					calcArr[10] = dragon.getAddsVar()[4];
					result[2] = (player.getAttack() * dragon.getAddsVar()[4] + player.getDefense() * dragon.getAddsVar()[5]) / 3000 + calcPower(calcArr);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		//神雕侠侣战力
		int xl = player.getDataInfo().intDataGet(ConstantsIntKey.xl);
		if (xl > 0) {
			int[] aftAdd = FormulaMarry.getAddv(xl);
			initArr(calcArr);
			for (int i = 0; i < aftAdd.length; i++) {
				calcArr[i] = aftAdd[i];
			}
			result[3] = calcPower(calcArr);
		}

		result[0] = result[1] + result[2] + result[3];
		return result;
	}

	/**
	 * 玩家基础战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcPlayerScore(Player player) {
		int[] result = new int[1];
		int[] calcArr = new int[15];
		// 玩家基础战力
		Vocation vocation = Context.getCongfigServer().getVocation(player.getVocationId());
		int[] arrBase = new int[4];
		// power
		arrBase[0] = vocation.getPower() + (player.getLevel() - 1) * vocation.getAddPower();
		// physical
		arrBase[1] = vocation.getPhysical() + (player.getLevel() - 1) * vocation.getAddPhysical();
		// agile
		arrBase[2] = vocation.getAgile() + (player.getLevel() - 1) * vocation.getAddAgile();
		// wit
		arrBase[3] = vocation.getWit() + (player.getLevel() - 1) * vocation.getAddWit();

		transfer(calcArr, player.getVocationId(), arrBase);
		result[0] = calcPower(calcArr);// 角色基础战力

		return result;
	}

	/**
	 * 装备战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcEquipScore(Player player) {
		int[] result = new int[6];
		Collection<Goods> equipList = player.getPlayerBoxs().getEquipList();

		int[] calcArr1 = new int[15];
		int[] calcArr2 = new int[15];
		int[] calcArr3 = new int[15];
		int[] calcArr4 = new int[15];// {0,hp,mp,attack,defence,hit,dodge,crit,tough,attackSpee,hurtAdd,hurtAbsorb,hurtReflex,hurtRemove,critAdd,0}
		int[] calcArr5 = new int[15];
		for (Goods e : equipList) {
			// 基本
			GoodsExt goodsExt = Context.getCacheCenter().getGoodsExtByLevel(e.getGoodsId(), 0);
			if (goodsExt != null) {
				calcArr5[5] += goodsExt.getAttack();
				calcArr5[6] += goodsExt.getDefense();
				calcArr5[7] += goodsExt.getHp();
				calcArr5[8] += goodsExt.getMp();
				
				if (e.getGoodsMode().getGoodTypeId() == EquipType.Pendant.goodTypeId()) {//护符收藏功能
					int percentAdd = player.getDataInfo().intDataGet(ConstantsIntKey.fhfv);
					if (percentAdd > 0 ) {
						calcArr5[7] += NumberProcesser.percentOnlyAddValue(e.getHp(), percentAdd);
						calcArr5[8] += NumberProcesser.percentOnlyAddValue(e.getMp(), percentAdd);
						calcArr5[5] += NumberProcesser.percentOnlyAddValue(e.getAttack(), percentAdd);
						calcArr5[6] += NumberProcesser.percentOnlyAddValue(e.getDefense(), percentAdd);
						//eSpeed += NumberProcesser.percentOnlyAddValue(e.getGoodsMode().getSpeed(), percentAdd);
					}
				}
				
			}

			// 追加等级加成
			int forgeAppend = 0;
			if (e.getForgeLevel() <= 20) {
				forgeAppend = e.getForgeLevel() * e.getGoodsMode().getAppend();
			} else {
				forgeAppend = e.getGoodsMode().getAppend() * 20 + (e.getGoodsMode().getAppend() * (e.getForgeLevel() - 20)) / 2;
			}
			if (e.getAttack() > 0) {
				calcArr1[5] += forgeAppend;// attack
			}
			if (e.getDefense() > 0) {
				calcArr1[6] += forgeAppend;// defense
			}
			if (e.getHp() > 0) {
				calcArr1[7] += forgeAppend;// hp
			}
			if (e.getMp() > 0) {
				calcArr1[8] += forgeAppend;// mp
			}

			GoodsExt goodsExtLevel = Context.getCacheCenter().getGoodsExtByLevel(e.getGoodsId(), e.getLevel());
			if (goodsExt != null) {
				calcArr2[5] += goodsExtLevel.getAttack() - goodsExt.getAttack();
				calcArr2[6] += goodsExtLevel.getDefense() - goodsExt.getDefense();
				calcArr2[7] += goodsExtLevel.getHp() - goodsExt.getHp();
				calcArr2[8] += goodsExtLevel.getMp() - goodsExt.getMp();
			}

			// 升星级数加成
			int[] append = Context.getGoodsServer().calculateGoodsStar(e.getGoodsMode(), e.getLevel());
			calcArr2[1] += append[0];// hit
			calcArr2[2] += append[1];// dodge
			calcArr2[3] += append[2];// crit
			calcArr2[4] += append[3];// tough

			// 镶嵌宝石加成
			if (!BlankUtils.isBlank(e.getGemMap())) {
				for (Integer hole : e.getGemMap().keySet()) {
					int id = e.getGemMap().get(hole);
					if (id > 0) {
						ModeGoodsInlay inlay = ModeGoodsInlay.get(id);
						calcArr3[5] += inlay.getAttack();
						calcArr3[6] += inlay.getDefense();
						calcArr3[7] += inlay.getHp();
						calcArr3[8] += inlay.getMp();
						calcArr3[9] += inlay.getSpeed();
					}
				}
			}
		}
		// 全套装备星级加成
		List<ModeGoodsStarSuit> list = ModeGoodsStarSuit.getStarSuite(equipList);
		for (ModeGoodsStarSuit s : list) {
			if (s.isActived()) {
				calcArr4[1] += s.getHit();
				calcArr4[2] += s.getDodge();
				calcArr4[3] += s.getCrit();
				calcArr4[4] += s.getTough();
				calcArr4[5] += s.getAttack();
				calcArr4[6] += s.getDefense();
				calcArr4[7] += s.getHp();
				calcArr4[8] += s.getMp();
			}
		}
		
		result[1] = calcPower(calcArr5);
		result[2] = calcPower(calcArr1);// 追加
		result[3] = calcPower(calcArr2);// 升星
		result[4] = calcPower(calcArr3);// 镶嵌
		result[5] = calcPower(calcArr4);// 星级套装
		result[0] = result[1] + result[2] + result[3] + result[4] + result[5];

		return result;
	}

	/**
	 * 技能战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcSkillScore(Player player) {
		int[] result = new int[5];
		int[] calcArr1 = new int[15];
		int[] calcArr2 = new int[15];
		// 帮派武功
		Map<Integer, Integer> skillMap = player.getDataInfo().getUnionSkillMap();
		if (!BlankUtils.isBlank(skillMap)) {
			for (Map.Entry<Integer, Integer> entry : skillMap.entrySet()) {
				if (entry.getValue() > 0) {
					UnionSkillConfig config = Context.getUnionServer().getUnionSkillConfig(entry.getKey().toString() + entry.getValue().toString());

					// 1:加命中,2:加闪避,3:加暴击,4:加韧性,5:加攻击,6:加防御,7:加血,8:加蓝,9:攻速
					switch (config.getType()) {
					case Constants.skillPassiveTypeHit:
						calcArr1[1] += config.getEffect();
						break;
					case Constants.skillPassiveTypeDodge:
						calcArr1[2] += config.getEffect();
						break;
					case Constants.skillPassiveTypeCrit:
						calcArr1[3] += config.getEffect();
						break;
					case Constants.skillPassiveTypeTough:
						calcArr1[4] += config.getEffect();
						break;
					case Constants.skillPassiveTypeAttack:
						calcArr1[5] += config.getEffect();
						break;
					case Constants.skillPassiveTypeDefense:
						calcArr1[6] += config.getEffect();
						break;
					case Constants.skillPassiveTypeHp:
						calcArr1[7] += config.getEffect();
						break;
					case Constants.skillPassiveTypeMp:
						calcArr1[8] += config.getEffect();
						break;
					case Constants.skillPassiveTypeSpeed:
						calcArr1[9] += config.getEffect();
						break;
					}
				}
			}
		}

		PlayerSkill playerSkill = Context.getSkillServer().getPlayerSkill(player.getPlayerId());
		Collection<Skill> skills = playerSkill.getsSkills();
		int vSkillPower = 0, cSkillPower = 0;
		if (skills != null && skills.size() > 0) {
			for (Skill e : skills) {
				SkillMode skillMode = e.getSkillMode();
				if (skillMode == null) {
					continue;
				}

				if (skillMode.getType() == SkillMode.typeMartial && skillMode.getPassiveAdds() != null) {// 绝世武功（被动）

					int[] skillAdd = skillMode.getPassiveAdds();
					calcArr2[1] += skillAdd[1];// 命中
					calcArr2[2] += skillAdd[2];// 闪避
					calcArr2[3] += skillAdd[3];// 暴击
					calcArr2[4] += skillAdd[4];// 韧性
					calcArr2[5] += skillAdd[5];// 攻击
					calcArr2[6] += skillAdd[6];// 防御
					calcArr2[7] += skillAdd[7];// 生命
					calcArr2[8] += skillAdd[8];// 魔法
					calcArr2[9] += skillAdd[9];// 攻速

				} else if (skillMode.getType() == SkillMode.typeVocational && skillMode.getEffectValue() > 0) {
					for (SkillGird skillGird : playerSkill.getShortcutGirds()) {
						if (!skillGird.isAreGoods() && skillGird.getId() == skillMode.getId()) {
							vSkillPower += calcPower(player.getAttack(), skillMode.getGroupNum(), skillMode.getEffectValue());// 职业武功（主动）
						}
					}

				} else if (skillMode.getType() == SkillMode.typeCheats && skillMode.getEffectValue() > 0) {
					for (SkillGird skillGird : playerSkill.getShortcutGirds()) {
						if (!skillGird.isAreGoods() && skillGird.getId() == skillMode.getId()) {
							cSkillPower += calcPower(player.getAttack(), skillMode.getGroupNum(), skillMode.getEffectValue());// 秘籍武功（主动）
						}
					}
				}
			}
		}
		int mSkillPower = calcPower(calcArr2);
		result[1] = vSkillPower;// 职业
		result[2] = cSkillPower;// 秘籍
		result[3] = mSkillPower;// 绝世
		result[4] = calcPower(calcArr1);// 帮派
		result[0] = result[1] + result[2] + result[3] + result[4];
		return result;
	}

	/**
	 * 徒弟战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcOneDisciple(Disciple disciple, int vocationId) {
		int[] result = new int[5];
		try {
			int[] calcArr = new int[15];

			int[] propertysArr = new int[4];
			// 徒弟基础一级属性
			FormulaDisciple.getBasePropertys(disciple, propertysArr);
			transfer(calcArr, vocationId, propertysArr);// 一级属性转换成二级属性
			result[1] = calcPower(calcArr);// 基础
			// 特训
			if (disciple.getDevilTimes() > 0 && disciple.getDevilTimes() <= DiscipleConfig.devilMaxTimes) {
				initArr(propertysArr);
				FormulaDisciple.getDevilPropertys(disciple, propertysArr);
				initArr(calcArr);
				transfer(calcArr, vocationId, propertysArr);
				result[2] = calcPower(calcArr);// 特训
			}

			// 独门劲功
			if (disciple.getGestSign() > 0) {
				initArr(calcArr);
				int[] gestAdd = DiscipleConfig.gestAddMap.get(disciple.getGestSign());
				calcArr[1] = gestAdd[5];// hit
				calcArr[2] = gestAdd[7];// dodge
				calcArr[3] = gestAdd[6];// crit
				calcArr[4] = gestAdd[2];// tough
				calcArr[5] = gestAdd[9];// attack
				calcArr[6] = gestAdd[4];// defence
				calcArr[7] = gestAdd[1];// hp
				calcArr[8] = gestAdd[3];// mp
				calcArr[9] = gestAdd[8];// speed
				result[3] = calcPower(calcArr);// 独门
			}

			// 技能、天赋
			DiscipleFeature feature = DiscipleFeature.getById(disciple.getFeatureType());
			if (feature != null && feature.getAdd() != null && disciple.getFeatureLevel() > 0) {
				initArr(calcArr);
				int add = feature.getAdd()[disciple.getFeatureLevel() - 1];
				switch (disciple.getFeatureType()) {
				case 1:
					calcArr[1] += NumberProcesser.percentOnlyAddValue(disciple.getPower(), add);
					break;
				case 2:
					calcArr[2] += NumberProcesser.percentOnlyAddValue(disciple.getAgile(), add);
					break;
				case 3:
					calcArr[3] += NumberProcesser.percentOnlyAddValue(disciple.getWit(), add);
					break;
				case 4:
					calcArr[4] += NumberProcesser.percentOnlyAddValue(disciple.getPhysical(), add);
					break;
				case 5:
					calcArr[5] += NumberProcesser.percentOnlyAddValue(disciple.getPower(), add);
					break;
				case 6:
					calcArr[6] += NumberProcesser.percentOnlyAddValue(disciple.getAgile(), add);
					break;
				case 7:
					calcArr[7] += NumberProcesser.percentOnlyAddValue(disciple.getPhysical(), add);
					break;
				case 8:
					calcArr[8] += NumberProcesser.percentOnlyAddValue(disciple.getWit(), add);
					break;
				default:
					break;
				}
				result[4] = calcPower(calcArr);// 天赋
			}

			initArr(calcArr);
			initArr(propertysArr);
			if (disciple.getDowerMap().isEmpty() == false) {
				for (Map.Entry<Integer, Integer> entry : disciple.getDowerMap().entrySet()) {
					int dowerId = entry.getKey();
					DiscipleDower dower = DiscipleDower.getById(dowerId);
					if (dower != null && dower.getAdd() != null) {
						int add = dower.getAdd()[entry.getValue() - 1];
						if (dowerId <= 14) {
							calcArr[dowerId] += add;
						}
						if (dowerId >= 21 && dowerId <= 24) {
							propertysArr[dowerId - 21] = add;
						}
					}
				}
			}
			if (propertysArr[0] > 0) {
				calcArr[1] += NumberProcesser.percentOnlyAddValue(disciple.getPower(), propertysArr[0]);
			}
			if (propertysArr[1] > 0) {
				calcArr[2] += NumberProcesser.percentOnlyAddValue(disciple.getAgile(), propertysArr[1]);
			}
			if (propertysArr[2] > 0) {
				calcArr[3] += NumberProcesser.percentOnlyAddValue(disciple.getWit(), propertysArr[2]);
			}
			if (propertysArr[3] > 0) {
				calcArr[4] += NumberProcesser.percentOnlyAddValue(disciple.getPhysical(), propertysArr[3]);
			}
			result[4] += calcPower(calcArr);// 技能加到师傅的二级属性

			initArr(propertysArr);
			initArr(calcArr);
			FormulaDisciple.getDowerAddSelf(disciple, propertysArr);// 技能加到自身的属性
			transfer(calcArr, vocationId, propertysArr);
			result[4] += calcPower(calcArr);
		} catch (Exception e) {
			e.printStackTrace();
		}

		result[0] = result[1] + result[2] + result[3] + result[4];
		return result;
	}

	/**
	 * 徒弟战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcDiscipleScore(Player player) {
		int[] result = new int[5];
		PlayerMartial playerMartial = Context.getDiscipleServer().getByPlayerId(player.getPlayerId());

		int[] oneResult = new int[4];
		if (!BlankUtils.isBlank(playerMartial)) {
			for (Disciple disciple : playerMartial.getDisciples()) {
				if (disciple.getCampId() <= 0) {// 在助阵中才计算
					continue;
				}

				DiscipleMode mode = disciple.getDiscipleMode();
				if (mode == null) {
					continue;
				}
				oneResult = calcOneDisciple(disciple, player.getVocationId());
				result[0] += oneResult[0];// 总
				result[1] += oneResult[1];// 基础
				result[2] += oneResult[2];// 特训
				result[3] += oneResult[3];// 独门
				result[4] += oneResult[4];// 技能+天赋
			}
		}

		return result;
	}

	/**
	 * 计算一只宠物战力
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcOnePet(Pet pet) {
		int[] result = new int[6];
		int[] calcArr1 = new int[15];
		int[] calcArr3 = new int[15];
		int[] calcArr4 = new int[15];

		int petSkillPower1 = 0, petSkillPower2 = 0, petSkillPower3 = 0;// 主动、被动
		PetMode petMode = Context.getPetServer().getPetMode(pet.getModeId());
		int coefficient = pet.getGrowth() * 10 * pet.getStar() * pet.getLevel() / 2;
		int growthBase = 1000;
		calcArr1[1] = coefficient * petMode.getHit() / growthBase;// hit
		calcArr1[2] = coefficient * petMode.getDodge() / growthBase;// dodge
		calcArr1[3] = coefficient * petMode.getCrit() / growthBase;// crit
		calcArr1[4] = coefficient * petMode.getTough() / growthBase;// tough
		calcArr1[5] = coefficient * petMode.getAttack() / growthBase;// attack
		calcArr1[6] = coefficient * petMode.getDefense() / growthBase;// defense
		if (coefficient * petMode.getHp() > 0) {//防止溢出
			calcArr1[7] = coefficient * petMode.getHp() / growthBase;// hp
		} else {
			calcArr1[7] = (int)(1L * coefficient * petMode.getHp() / growthBase);// hp
		}
		calcArr1[8] = coefficient * petMode.getMp() / growthBase;// mp
		calcArr1[9] = coefficient * petMode.getSpeed() / growthBase;// speed

		result[1] = calcPower(calcArr1);// 基础

		// 悟性修炼
		if (pet.getPerception() > 0) {
			result[2] = result[1] * ConstantsModel.petPreAdd[pet.getPerception() - 1] / 1000;// 悟性修炼
		}
		// 灵性点化
		if (pet.getSpirit() > 0) {
			result[5] = result[1] * ConstantsModel.petSpiritAdd[pet.getSpirit() - 1] / 1000;
		}

		// 领悟技能
		int[] skillIds = pet.getSkillIds();
		if (skillIds != null && skillIds.length > 0) {
			for (int eId : skillIds) {
				SkillMode skillMode = Context.getSkillServer().getSkillMode(eId);
				if (skillMode != null) {
					// 主动技能
					if ((skillMode.getPassiveType() == 0 || skillMode.getPassiveType() == Constants.skillAddBlood) && skillMode.getEffectValue() > 0) {
						petSkillPower1 += calcPower(pet.getAttack(), skillMode.getGroupNum(), skillMode.getEffectValue());
					}

					if (skillMode.getPassiveType() == Constants.skillGotBlood || skillMode.getPassiveType() == Constants.skillGotMagic) {
						petSkillPower3 += skillMode.getPassiveValue() / 100;
					}

					// 被动技能
					if (skillMode.getPassiveType() > 0 && skillMode.getPassiveType() <= 9 && skillMode.getPassiveValue() > 0) {
						switch (skillMode.getPassiveType()) {
						case Constants.skillPassiveTypeHit:
							calcArr3[1] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeDodge:
							calcArr3[2] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeCrit:
							calcArr3[3] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeTough:
							calcArr3[4] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeAttack:
							calcArr3[5] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeDefense:
							calcArr3[6] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeHp:
							calcArr3[7] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeMp:
							calcArr3[8] += skillMode.getPassiveValue();
							break;
						case Constants.skillPassiveTypeSpeed:
							calcArr3[9] += skillMode.getPassiveValue();
							break;
						}
					}
				}
			}
		}

		// 魂力
		Map<Integer, Soul> huntsMap = pet.getHuntsMap();
		if (huntsMap != null && !huntsMap.isEmpty()) {
			for (Soul e : huntsMap.values()) {
				PetSoul petSoul = Context.getPetServer().getSoul(e.getId());
				if (petSoul != null && petSoul.getAddV() != null) {
					int[] skillAdd = petSoul.getAddV();
					calcArr4[1] += skillAdd[0];// hit
					calcArr4[2] += skillAdd[1];// dodge
					calcArr4[3] += skillAdd[2];// crit
					calcArr4[4] += skillAdd[3];// tough
					calcArr4[5] += skillAdd[4];// attack
					calcArr4[6] += skillAdd[5];// defence
					calcArr4[7] += skillAdd[6];// hp
					calcArr4[8] += skillAdd[7];// mp
					calcArr4[9] += skillAdd[8];// speed
				}
			}
		}
		petSkillPower2 = calcPower(calcArr3);// 被动技能

		result[3] = petSkillPower1 + petSkillPower2 + petSkillPower3;// 领悟技能（主动+被动）
		result[4] = calcPower(calcArr4);// 魂力
		result[0] = result[1] + result[2] + result[3] + result[4] + result[5];// 总和
		return result;
	}

	/**
	 * 宠物战力评分
	 * 
	 * @param player
	 * @return
	 */
	public static int[] calcPetScore(Player player) {
		int[] result = new int[6];

		Pet ePet = player.getDataInfo().getPet();

		if (ePet != null) {// 宠物在出战中
			result = calcOnePet(ePet);
		}

		return result;
	}

	public static int calcPower(int[] calcArr) {
		int power = calcArr[7] / 10 + (calcArr[5] + calcArr[6]) / 3 + (calcArr[1] + calcArr[2] + calcArr[3] + calcArr[4] + calcArr[9]) / 2 + calcArr[10]
				+ calcArr[11] + calcArr[12] + calcArr[13] + calcArr[14];
		power = power / 10;
		return power;
	}

	/**
	 * 主动技能战力计算公式
	 * 
	 * @param attack
	 * @param groupNum
	 * @param percent
	 * @return
	 */
	public static int calcPower(int attack, int groupNum, int percent) {
		int power = (attack / 300) * (groupNum * percent) / 100 / 7;
		return power;
	}

	/**
	 * 一级属性转二级属性计算
	 * 
	 * @param calcArr
	 * @param vocation
	 * @param propertyArr
	 *            一级属性数组
	 * @return
	 */
	public static int[] transfer(int[] calcArr, int vocationId, int[] propertyArr) {

		int ePhysical = 0, ePower = 0, eWit = 0, eAgile = 0;
		ePower = propertyArr[0];
		ePhysical = propertyArr[1];
		eAgile = propertyArr[2];
		eWit = propertyArr[3];
		switch (vocationId) {
		case 1:
			calcArr[1] += ePower * 1;// 命中
			calcArr[2] += eAgile * 1;// 闪避
			calcArr[3] += eWit * 1;// 暴击
			calcArr[4] += ePhysical * 12 / 10;// 韧性
			calcArr[5] += ePower * 3;// 攻击
			calcArr[6] += ePhysical * 3;// 防御
			calcArr[7] += ePhysical * 7;// 血量 ，职业平衡,武者兑换血量增加1点，由6点改为7点。
			calcArr[8] += eWit * 5;// 气力
			calcArr[9] += eAgile * 1;// 速度
			break;
		case 2:
			calcArr[1] += ePower * 2;
			calcArr[2] += eAgile * 1;
			calcArr[3] += eWit * 1;
			calcArr[4] += ePhysical * 12 / 10;
			calcArr[5] += eWit * 3;
			calcArr[6] += ePhysical * 3;
			calcArr[7] += ePhysical * 5;
			calcArr[8] += eWit * 5;
			calcArr[9] += eAgile * 1;
			break;
		case 3:
			calcArr[1] += ePower * 2;
			calcArr[2] += eAgile * 1;
			calcArr[3] += eWit * 1;
			calcArr[4] += ePhysical * 12 / 10;
			calcArr[5] += eAgile * 3;
			calcArr[6] += ePhysical * 3;
			calcArr[7] += ePhysical * 6;
			calcArr[8] += eWit * 5;
			calcArr[9] += eAgile * 1;
			break;
		default:
			break;
		}
		return calcArr;
	}

	public static void initArr(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			arr[i] = 0;
		}
	}
}
